home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch10 / raw2poly.c < prev    next >
C/C++ Source or Header  |  1994-05-16  |  1KB  |  64 lines

  1. ///////////////////////////////////////////
  2. //
  3. // RAW TO POLYRAY CONVERTER  RAW2POLY.C
  4. //
  5. //////////////////////////////////////////
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. void main(int argc, char *argv[]) {
  11.  
  12.   FILE *infile, *outfile;
  13.   float x1, y1, z1,
  14.     x2, y2, z2,
  15.     x3, y3, z3;
  16.   int count = 0;
  17.  
  18.   if(argc < 2) {
  19.     printf("Usage: RAW2POLY inputfile outputfile\n");
  20.     exit(1);
  21.   }
  22.  
  23.   if ((infile = fopen(argv[1], "rt")) == NULL) {
  24.     printf("Can't open %s!\n",argv[1]);
  25.     exit(1);
  26.   }
  27.  
  28.   if ((outfile = fopen(argv[2], "wt")) == NULL) {
  29.     printf("Can't open %s!\n",argv[2]);
  30.     exit(1);
  31.   }
  32.  
  33.  
  34.   fprintf(outfile," object{\n");
  35.  
  36.   while (!feof(infile)) {
  37.     if ((fscanf(infile,"%f",&x1) > 0) &&
  38.     (fscanf(infile,"%f",&y1) > 0) &&
  39.     (fscanf(infile,"%f",&z1) > 0) &&
  40.     (fscanf(infile,"%f",&x2) > 0) &&
  41.     (fscanf(infile,"%f",&y2) > 0) &&
  42.     (fscanf(infile,"%f",&z2) > 0) &&
  43.     (fscanf(infile,"%f",&x3) > 0) &&
  44.     (fscanf(infile,"%f",&y3) > 0) &&
  45.     (fscanf(infile,"%f",&z3) > 0)) {
  46.     if(count)
  47.       fprintf(outfile, "   + object {");
  48.     else
  49.       fprintf(outfile, "     object {");
  50.     fprintf(outfile, " polygon 3, ");
  51.     fprintf(outfile, "<%g, %g, %g>,",x1,y1,z1);
  52.     fprintf(outfile, "<%g, %g, %g>,",x2,y2,z2);
  53.     fprintf(outfile, "<%g, %g, %g>}\n" ,x3,y3,z3);
  54.     count++;
  55.     }
  56.   }
  57.  
  58.   fprintf(outfile,"       shiny_red\n }\n");
  59.  
  60.   fclose(infile);
  61.   fclose(outfile);
  62.  
  63. }
  64.